/*
 * selection_sort.cpp
 *
 *  Created on: May 3, 2014
 *      Author: Lhmily
 */
#include "../header/base.h"
#include "../header/compare.h"

template<typename Elem, typename Comp>
void selection_sort(Elem A[], int n) {
	int index = 0, i = 0, j = 0;
	for (i = 0; i < n - 1; ++i) {
		index = i;
		for (j = n - 1; j > i; --j)
			if (Comp::prior(A[j], A[index]))
				index = j;
		swap(A, i, index);
	}
}

template<typename E, typename Comp>
void sort(E* array, int n) {
	selection_sort<E, Comp>(array, n);
}

#include "../test.cpp"

int main(int argc, char **argv) {

	return testMain<minintCompare>(argc, argv); //
}
